/**
 * 
 */
package me.myachievements.web.tag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import me.myachievements.persistence.goal.Goal;
import me.myachievements.persistence.goal.GoalPersistenceManager;
import me.myachievements.persistence.tag.Tag;
import me.myachievements.persistence.tag.TagPersistenceManager;

import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.ListMultipleChoice;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
 * @author besseym
 *
 */
public class GoalTagRemoveForm extends GoalTagForm {
	
	private ListMultipleChoice<Tag> tagListMultipleChoice;

	/**
	 * @param id
	 */
	public GoalTagRemoveForm(String id, final Goal goal) {
		
		super(id, goal);
		
		ChoiceRenderer<Tag> renderer = new ChoiceRenderer<Tag>("value", "id");
		
		AssociatedTagsModel associatedTagsModel = new AssociatedTagsModel(goal.getId());
		tagListMultipleChoice = new ListMultipleChoice<Tag>("tagList", associatedTagsModel, renderer);
		add(tagListMultipleChoice);
	}
	
	/*
	 * (non-Javadoc)
	 * @see me.myachievements.web.tag.GoalTagForm#onSubmit()
	 */
	@Override
	public void onSubmit(){
		
		GoalTagFormModel tagGoalFormModel = this.getModelObject();
		this.getGoal().getTags().removeAll(tagGoalFormModel.getTagList());
		
		this.tagListMultipleChoice.detach();
		
		super.onSubmit();
		
		//this.tagListMultipleChoice.setChoices(new ArrayList<Tag>(this.getGoal().getTags()));
	}

}
